package cn.enjoyedu.callback;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.stereotype.Component;

/**
 * 类说明：发送者确认的回调
 * 配置
 * <rabbit:template id="rabbitTemplate"
 * 					 connection-factory="rabbitConnectionFactory"
 *     mandatory="true"
 *     return-callback="sendReturnCallback"
 *     confirm-callback="confirmCallback">
 *     中
 *     confirm-callback="confirmCallback"
 *     实现
 */
@Component
public class ConfirmCallback implements RabbitTemplate.ConfirmCallback {
    @Override
    public void confirm(CorrelationData correlationData,
                        boolean ack,
                        String cause) {
        if(ack){
            System.out.println("消息发送给mq成功");
        }else{
            System.out.println("消息发送给mq失败，原因："+cause);
        }

    }
}
